const mongoose = require("mongoose")
const { Schema, model } = mongoose

const userSchema = new Schema({
    __v: {
        type: Number,
        select: false
    },
    //用户名
    username: {
        type: String,
        required: true
    },
    // 密码
    password: {
        type: String,
        required: true,
        select: false
    },
    // 用户电话
    phone: {
        type: String,
        required: true,
        select: false
    },
    // 用户头像
    avatar_url: {
        type: String,
        default: "http://localhost:8000/uploads/upload_8ceee7597f3fb11996a0a88f5599f497.jpg"
    },
    // 封面图片
    cover: {
        type: String
    },
    // 性别
    gender: {
        type: String,
        enum: ["male", "female"],
        default: "male",
        required: true
    },
    // 签名
    headline: {
        type: String,
        default: "这人很懒，什么也没有留下"
    },
    // 地址
    locations: {
        type: String,
    },
    // 职业
    business: {
        type: String,
    },
    // 公司和职位
    employments: {
        type: [{
            company: String,
            job: String
        }],
    },
    // 教育经历
    educations: {
        type: [{
            school: { type: Schema.Types.ObjectId, ref: "Topic" },
            major: { type: Schema.Types.ObjectId, ref: "Topic" },
            diploma: { type: Number, enum: [1, 2, 3, 4, 5] },
            entrance_year: { type: Number },
            graduation_year: { type: Number }
        }],
        select: false
    },
    // 关注用户
    following: {
        type: [{
            type: Schema.Types.ObjectId,
            ref: "User"
        }],
        select: false
    },
    // 关注话题
    followingTopics: {
        type: [{
            type: Schema.Types.ObjectId,
            ref: "Topic"
        }],
        select: false
    },
    likingAnswers: {
        type: [{
            type: Schema.Types.ObjectId,
            ref: "Answer"
        }],
        select: false
    },
    dislikingAnswers: {
        type: [{
            type: Schema.Types.ObjectId,
            ref: "Answer"
        }],
        select: false
    },
    collectingQuestions: {
        type: [{
            type: Schema.Types.ObjectId,
            ref: "Question"
        }],
        select: false
    }
}, { timestamps: true })

module.exports = model("User", userSchema)